<?php

/***************************************************************\
* FILE:		sys/pages/topic.inc
* SECTION:	pages > items
* FUNCTION:	display a topic
* USES:	
* INCLUDES:	/sys/itemfunctions.inc	
* PRODUCES:	
* LAUNCHES:	
\***************************************************************/

include_once('sys/itemfunctions.inc');

/**
 * adds extra access checks, dependent on page state
 */
function page_inc_check_access() {
	item_page_inc_check_access();
}

/**
 * appropriate page action interpretations
 */
function page_inc_execute_action($action) {
	switch($action) {
		default:
			item_page_inc_execute_action($action, 'topic');
			break;
	}
}

/**
 * execute page logic
 */
function page_inc_execute() {
	global $PAGE;
	$CONTENT = array();

	$where = "ITEM.item_id = {$PAGE['id']} AND \n\t";
	$where .= "ITEM.author = M1.user_id AND \n\t";
	$where .= "ITEM.editor = M2.user_id";

	$sql = db_query_select(array(array('*'),array(),"M1.nick AS nick_author, M2.nick AS nick_editor"), array('ITEM','MEMBER AS M1, MEMBER AS M2', 'DUMMY'), $where);
	$sqlresult = db_do_query($sql);

	if (db_num_rows($sqlresult) !=1)
		errorpage(404);

	$CONTENT['topic'] = db_fetch_array($sqlresult);

	if ($CONTENT['topic']['deleted'])
		errorpage(404);
	
	$CONTENT['title'] = $CONTENT['topic']['title'];
	$CONTENT['owner'] = $CONTENT['topic']['author'];
		
	$PAGE['content'] = $CONTENT;
	
	item_page_inc_execute('topic');
}


/**
 * dress up page content using skin stuff
 */
function page_inc_dress() {
	global $PAGE;
	item_page_inc_dress_before();
	item_page_inc_dress_after();
}

?>
